package com.neuedu.collection.Map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class HashMapDemo {
    public static void main(String[] args) {
        HashMap map = new HashMap();
        map.put("001","张三");
        map.put("002","张四");
        map.put("003","张五");
        map.put("004","张六");
        map.put("005","张七");
        map.put("006","张三");

        System.out.println(map.size());
        Object value =  map.get("004");
        System.out.println(value);

        HashMap<String,Teacher>  map2 = new HashMap<>();
        map2.put("李四",new Teacher("李四",25));
        map2.put("李五",new Teacher("李五",26));
        map2.put("李六",new Teacher("李六",27));
        map2.put("李七",new Teacher("李七",28));
        map2.put("李八",new Teacher("李八",29));
        Teacher  teacher =  map2.get("李八");
        System.out.println(teacher);
        /*
        *   姓名
        *   单位
        *   手机
        *   私人/电子邮件
        *   备注
        *
        * */
        Friend  f1 = new Friend("王三","哈西万达","1801234567","wangsan@163.com","");
        Friend  f2 = new Friend("王四","金爵万象","1821234567","wangsi@163.com","");
        Friend  f3 = new Friend("王五","溪树庭院","1831234567","wangwu@126.com","");

        Map<String,Friend>   map3 = new HashMap<>();
        map3.put("王三",f1);
        map3.put("王四",f2);
        map3.put("王五",f3);
        System.out.println(map3);

        Set<String> set =map3.keySet();
        System.out.println(set);

        Friend  f = (Friend) map3.get("王三");
        System.out.println(f);

        set.forEach(x-> System.out.println(x+":"+ map3.get(x) ));
        System.out.println("=================");
        for(Iterator  it = set.iterator(); it.hasNext();){
             String key = it.next().toString();
             Friend  friend =  map3.get(key);
            System.out.println(key+":"+friend);
        }

        HashMap<String,Friend>   map4 = new HashMap<>();
        map4.put("王六",new Friend("王六","学府路","1851234567","wangliu@126.com",""));
        map4.putAll(map3);
        System.out.println(map4);

        map4.remove("王五");
        System.out.println(map4);

        boolean   find = map4.containsKey("王五");
        System.out.println(find);
        System.out.println("=============");
        System.out.println(map);
        find = map.containsValue("张三");
        System.out.println(find);

        System.out.println(map);
        Set<Map.Entry<String,String> > set2 =   map.entrySet();
        for(  Map.Entry<String,String>   m  :set2){
            String  k = m.getKey();
            String   v = m.getValue();
            if(v.equals("张三"))
                continue;
            System.out.println(k+":"+v);
        }


    }
}
